@import '../theme/color.scss';
@import './font';

@mixin border-position-radius($position: left) {
  border-top-#{$position}-radius: 0;
  border-bottom-#{$position}-radius: 0;
}

.devui-form-controls input[type='text'],
.devui-form-controls input[type='password'],
[dTextInput] {
  width: 100%;
  height: 28px;
}

[dTextArea] {
  width: 100%;
}

.devui-form-controls textarea,
[dTextInput],
[dTextarea] {
  box-sizing: border-box;
  padding: 4px 10px;
  color: $devui-text;
  vertical-align: middle;
  border: 1px solid $devui-form-control-line;
  border-radius: 2px;
  outline: none;
  background-color: $devui-base-bg;

  &:not([disabled]):not(.disabled):not(.devui-disabled):not(.error):not(.devui-error) {
    &:hover {
      border-color: $devui-form-control-line-hover;
    }

    &:focus {
      border-color: $devui-form-control-line-active;
    }
  }

  &[disabled],
  &.disabled,
  &.devui-disabled {
    &,
    &:hover {
      cursor: not-allowed;
      background-color: $devui-disabled-bg;
      border-color: $devui-disabled-line;
      color: $devui-disabled-text;
    }
  }
}

.devui-form-controls textarea,
[dTextarea] {
  width: 100%;
}

// input 样式
.devui-input-group {
  position: relative;
  display: table;
  border-collapse: separate;
}

.devui-input-group-addon {
  border: 1px solid $devui-form-control-line;
  border-radius: 2px;
  display: table-cell;
  padding: 0 10px;
  text-align: center;

  &:last-child {
    @include border-position-radius(left);

    border-left: 0;
  }

  &:first-child {
    @include border-position-radius(right);

    border-right: 0;
  }
}

.devui-input {
  outline: none;
  background-color: $devui-base-bg;
  border: 1px solid $devui-form-control-line;
  border-radius: 2px;
  padding: 5px 10px;
  line-height: 16px; // 解决ie中文字不居中，由于height28px，有10px的padding和2px的border，剩余16px，使用其他的会使文字不居中
  font-size: $devui-font-size;
  color: $devui-text;
  width: 100%;
  display: block;
  cursor: text;
  height: 28px;

  &:hover {
    border-color: $devui-form-control-line-hover;
  }

  &:focus {
    border-color: $devui-form-control-line-active;
  }

  &[disabled],
  &.disabled,
  &.devui-disabled {
    &,
    &:hover,
    &:focus,
    &:hover:focus {
      border-color: $devui-disabled-line;
      color: $devui-disabled-text;
      background-color: $devui-disabled-bg;
      cursor: not-allowed;
    }
  }

  &::placeholder {
    color: $devui-placeholder;
  }

  &.devui-search-in-dropdown {
    margin: 0;
    border: none;
    padding: 5px 26px 5px 10px;
    background-color: $devui-embed-search-bg;
    color: $devui-text;

    &:-ms-input-placeholder {
      color: $devui-placeholder;
    }

    &:hover {
      background-color: $devui-embed-search-bg-hover;
    }
  }

  .devui-input-group > & {
    display: table-cell;
  }

  .devui-input-group > &:first-child {
    @include border-position-radius(right);
  }

  .devui-input-group > &:last-child {
    @include border-position-radius(left);
  }

  .devui-input-group > &:not(:first-child):not(:last-child) {
    border-radius: 0;
  }
}

.devui-input-lg {
  font-size: $devui-font-size-page-title;
  line-height: 20px; // 同devui-input
  height: 32px;
}

.devui-input-sm {
  font-size: $devui-font-size;
  line-height: 14px; // 同devui-input
  height: 26px;
}

// dropdown 公共样式
.devui-dropup,
.devui-dropdown {
  position: relative;
}

.devui-form-group {
  position: relative;
}

.devui-form-control {
  color: $devui-text;
  background-color: $devui-base-bg;
  padding: 5px 10px;
  border: 1px solid $devui-form-control-line;
  display: block;
  width: 100%;
  height: 28px;
  border-radius: 2px;
  outline: 0;

  &[disabled],
  &.disabled,
  &.devui-disabled {
    &,
    &:hover,
    &:focus {
      border-color: $devui-disabled-line;

      &,
      & > input {
        color: $devui-disabled-text;
        background-color: $devui-disabled-bg;
        cursor: not-allowed;
      }
    }
  }

  &:hover {
    border-color: $devui-form-control-line-hover;
  }

  &:focus {
    border-color: $devui-form-control-line-active;
  }
}

:not(.devui-dropdown-origin-wrapper):not(.multiple-label-auto-complete-disabled) {
  > .devui-dropdown-origin {
    position: relative;
    z-index: 1;
  }

  > .devui-dropdown-origin:hover:not([disabled]):not(.disabled):not(.devui-disabled):not(:focus):not(.devui-dropdown-origin-open) {
    border-color: $devui-form-control-line-hover;
  }

  > .devui-dropdown-origin:focus:not([disabled]):not(.disabled):not(.devui-disabled) {
    outline: none;
    border-color: $devui-form-control-line-active;

    &:not(.devui-select-underlined-border):not(.devui-dropdown-no-border) {
      box-shadow: 0 2px 5px 0 $devui-shadow;
    }
  }

  > .devui-dropdown-origin.devui-dropdown-origin-open:not([disabled]):not(.disabled):not(.devui-disabled) {
    outline: none;
    border-color: $devui-connected-overlay-line;
    border-radius: 2px 2px 0 0;

    &:not(.devui-select-underlined-border):not(.devui-dropdown-no-border) {
      box-shadow: 0 2px 5px 0 $devui-shadow;
    }
  }

  > .devui-dropdown-origin.devui-dropdown-origin-open:not(.devui-no-border):not([disabled]):not(.disabled):not(.devui-disabled):not(.devui-dropdown-no-border) {
    z-index: 1052; // 为了让dividing边框覆盖cdk边框颜色

    & ~ .devui-form-control-feedback {
      z-index: 1052;
    }

    &.devui-dropdown-origin-bottom {
      border-bottom-color: $devui-dividing-line;
      box-shadow: none;

      &::after {
        content: '';
        width: 100%;
        height: 1px;
        background-color: $devui-dividing-line;
        position: absolute;
        z-index: 1001;
        left: 0;
        top: 100%;
      }
    }

    &.devui-dropdown-origin-top {
      border-top-color: $devui-dividing-line;

      &:not(.devui-select-underlined-border) {
        box-shadow: 0 2px 5px 0 $devui-shadow;
      }

      &::after {
        content: '';
        width: 100%;
        height: 1px;
        background-color: $devui-dividing-line;
        position: absolute;
        z-index: 1001;
        left: 0;
        top: -1px;
      }
    }
  }
}

.devui-dropdown-origin-wrapper {
  color: $devui-text;
  background-color: $devui-base-bg;
  min-height: 28px;

  & > .devui-input,
  & > .devui-form-control {
    height: 26px;
  }

  &:not(.devui-select-underlined-border) {
    border: 1px solid $devui-form-control-line;
    border-radius: 2px;
  }

  .devui-form-control,
  .devui-form-control:hover,
  .devui-form-control:focus,
  .devui-form-control:focus:hover,
  .devui-input-group-addon,
  .devui-input-group-addon:hover,
  .devui-input-group-addon:focus,
  > .devui-dropdown-default,
  > .devui-dropdown-default:hover,
  > .devui-dropdown-default:active,
  > .devui-dropdown-default:focus {
    position: relative;
    z-index: 1001;
    border-color: transparent;
  }

  &[disabled],
  &.disabled,
  &.devui-disabled {
    .devui-form-control,
    .devui-form-control:hover,
    .devui-form-control:focus,
    .devui-form-control:focus:hover,
    .devui-input-group-addon,
    > .devui-dropdown-default,
    > .devui-dropdown-default:hover,
    > .devui-dropdown-default:active,
    > .devui-dropdown-default:focus {
      background-color: $devui-disabled-bg;
    }
  }

  &:not([disabled]):not(.disabled):not(.devui-disabled):not(.devui-error) {
    .devui-form-control:not([disabled]):not(.disabled):not(.devui-disabled):not(.devui-error),
    .devui-form-control:not([disabled]):not(.disabled):not(.devui-disabled):not(.devui-error):hover,
    .devui-form-control:not([disabled]):not(.disabled):not(.devui-disabled):not(.devui-error):focus,
    .devui-form-control:not([disabled]):not(.disabled):not(.devui-disabled):not(.devui-error):focus:hover,
    .devui-input-group-addon,
    > .devui-dropdown-default,
    > .devui-dropdown-default:hover,
    > .devui-dropdown-default:active,
    > .devui-dropdown-default:focus {
      background-color: $devui-base-bg;
    }
  }
}

// css选择器不可合并，否则css解析器总是会失败
input::-moz-placeholder {
  color: $devui-placeholder;
}

input:-ms-input-placeholder {
  color: $devui-placeholder;
}

input::-webkit-input-placeholder {
  color: $devui-placeholder;
}

/* status style start */

/* border color and background */
[dTextInput]:not([disabled]):not(.disabled):not(.devui-disabled).error,
[dTextarea]:not([disabled]):not(.disabled):not(.devui-disabled).error,
[dTextInput]:not([disabled]):not(.disabled):not(.devui-disabled).devui-error,
[dTextarea]:not([disabled]):not(.disabled):not(.devui-disabled).devui-error {
  border-color: $devui-danger-line;
  background-color: $devui-danger-bg;
}

[dDatePicker]:not([disabled]):not(.disabled):not(.devui-disabled).devui-error {
  background-color: $devui-danger-bg;
}

d-select:not([disabled]):not(.disabled):not(.devui-disabled):not(.devui-dropdown-origin-wrapper):not(.multiple-label-auto-complete-disabled).devui-error {
  div.devui-dropdown-origin.devui-dropdown-origin-wrapper.devui-dropup,
  div.devui-dropdown-origin.devui-dropdown-origin-wrapper.devui-dropdown {
    border-color: $devui-danger-line;

    .devui-form-group .devui-input.devui-form-control.devui-select-input:not(.devui-select-search),
    .devui-form-group .devui-select-input:not(.devui-select-search) + .devui-form-control-feedback {
      background-color: $devui-danger-bg;
    }
  }
}

d-editable-select:not([disabled]):not(.disabled):not(.devui-disabled).devui-error {
  .devui-form-group:not(.devui-dropdown-origin-wrapper):not(.multiple-label-auto-complete-disabled) {
    input.devui-form-control.devui-dropdown-origin {
      border-color: $devui-danger-line;
      background-color: $devui-danger-bg; /* TODO: open时，下边框颜色 */
    }
  }
}

d-input-number:not([disabled]):not(.disabled):not(.devui-disabled).devui-error {
  .input-box:not(:disabled) {
    border-color: $devui-danger-line;
    background-color: $devui-danger-bg;
  }
}

d-multi-auto-complete:not([disabled]):not(.disabled):not(.devui-disabled).devui-error {
  :not(.devui-dropdown-origin-wrapper):not(.multiple-label-auto-complete-disabled) {
    &.multiple-label-auto-complete.multiple-label-auto-complete-border ul.devui-dropdown-origin {
      border-color: $devui-danger-line;
      background-color: $devui-danger-bg;
    }

    input[dAutoComplete] {
      background-color: $devui-danger-bg;
    }
  }
}

d-tags-input:not([disabled]):not(.disabled):not(.devui-disabled).devui-error {
  :not(.devui-dropdown-origin-wrapper):not(.multiple-label-auto-complete-disabled) {
    div.devui-tags.devui-form-control {
      border-color: $devui-danger-line;
      background-color: $devui-danger-bg;
    }

    input.devui-input {
      background-color: $devui-danger-bg;
    }
  }
}

d-tree-select:not([disabled]):not(.disabled):not(.devui-disabled).devui-error {
  :not(.devui-dropdown-origin-wrapper):not(.multiple-label-auto-complete-disabled) {
    & > div.devui-select-input.devui-dropdown-origin.devui-tree-select-input {
      border-color: $devui-danger-line;
      background-color: $devui-danger-bg; /* TODO: open时，下边框颜色 */
    }
  }
}

d-search:not([disabled]):not(.disabled):not(.devui-disabled).devui-error {
  input.devui-input {
    border-color: $devui-danger-line;
    background-color: $devui-danger-bg;
  }
}

/* border color only */
d-editor-md:not([disabled]):not(.disabled):not(.devui-disabled).devui-error {
  border-color: $devui-danger-line;
}

d-editor:not([disabled]):not(.disabled):not(.devui-disabled).devui-error {
  .ql-toolbar,
  .ql-container {
    border-color: $devui-danger-line;
  }
}

d-form-control {
  d-search {
    width: 100%;
  }
}

.devui-form-controls.devui-form-control-has-feedback {
  [dTextInput],
  [dTextarea] {
    padding-right: 28px;
  }

  d-search {
    .devui-search {
      .devui-search-icon {
        right: 24px;
      }

      .devui-search-line {
        right: 60px;
      }

      .devui-search-clear {
        right: 60px;
      }

      .devui-input.devui-icon-left {
        padding-right: 30px;
      }

      .devui-input {
        padding-right: 54px;
      }

      .devui-input.devui-clear-exit {
        padding-right: 84px;
      }

      .devui-search-line.devui-search-line-sm {
        right: 60px;
      }

      .devui-search-clear.devui-search-clear-sm {
        right: 60px;
      }

      .devui-input.devui-input-sm {
        padding-right: 54px;
      }

      .devui-input.devui-clear-exit.devui-input-sm {
        padding-right: 84px;
      }

      .devui-search-line.devui-search-line-lg {
        right: 70px;
      }

      .devui-search-clear.devui-search-clear-lg {
        right: 70px;
      }

      .devui-input.devui-input-lg {
        padding-right: 60px;
      }

      .devui-input.devui-clear-exit.devui-input-lg {
        padding-right: 95px;
      }
    }
  }

  d-select {
    .devui-form-group {
      .devui-select-input {
        padding-right: 48px;
      }

      .devui-form-control-feedback {
        right: 24px;
      }
    }
  }

  d-tree-select {
    vertical-align: middle;

    .devui-tree-select .devui-select-input.devui-tree-select-input {
      padding-right: 52px;
    }

    .devui-tree-select .devui-select-chevron-icon {
      right: 34px;
    }
  }

  d-input-number {
    width: 100%;

    .input-control-buttons {
      right: 32px;
    }

    .input-box {
      padding-right: 32px;
    }

    &:hover .input-box:not(.disabled) {
      padding-right: 58px;
    }
  }

  d-tags-input {
    .devui-tags {
      padding-right: 28px;
    }
  }

  d-multi-auto-complete {
    .multiple-label-auto-complete ul {
      padding-right: 28px;
    }
  }

  d-editable-select {
    .devui-form-group.devui-has-feedback > .devui-form-control-feedback {
      right: 24px;
    }

    & > div > .devui-form-control {
      padding-right: 48px;
    }
  }

  [dDatePicker].devui-form-control {
    padding-right: 32px;
  }
}

/* status style end */
